package com.gs.SynAntiWandering.model;

import com.gs.SynAntiWandering.callback.Callback;
import com.gs.SynAntiWandering.model.listener.OnResultListener;
import com.gs.SynAntiWandering.util.OKHttpUtil;

import java.io.IOException;
import java.lang.reflect.Type;

public class MemberModel {
    public void getData(Object query, final OnResultListener listener, Type typeofT) {
        OKHttpUtil.getInstance().postAsync(OKHttpUtil.NET_URL + "/api/members",
                query, new Callback() {
                    @Override
                    public void onSuccess(Object obj) {
                        listener.onSuccess(obj);
                    }

                    @Override
                    public void onFailed(Exception e) {
                        listener.onFails(e);
                    }
                }, typeofT);
    }

    public void members(String id, final OnResultListener lisentener,
                       Type typeofT) throws IOException {
        OKHttpUtil.getInstance().getAsync(OKHttpUtil.NET_URL + "/api/members?id=" + id, new Callback() {
            @Override
            public void onSuccess(Object obj) {
                lisentener.onSuccess(obj);
            }

            @Override
            public void onFailed(Exception e) {
                lisentener.onFails(e);
            }
        }, typeofT);
    }

    public void delete(String id, final OnResultListener lisentener,
                       Type typeofT) throws IOException {
        OKHttpUtil.getInstance().getAsync(OKHttpUtil.NET_URL + "/api/members/delete?id=" + id, new Callback() {
            @Override
            public void onSuccess(Object obj) {
                lisentener.onSuccess(obj);
            }

            @Override
            public void onFailed(Exception e) {
                lisentener.onFails(e);
            }
        }, typeofT);
    }

    public void add(Object bean, final OnResultListener lisentener,
                    Type typeofT) throws IOException {
        OKHttpUtil.getInstance().postAsync(OKHttpUtil.NET_URL + "/api/members/add", bean, new Callback() {
            @Override
            public void onSuccess(Object obj) {
                lisentener.onSuccess(obj);
            }

            @Override
            public void onFailed(Exception e) {
                lisentener.onFails(e);
            }
        },  typeofT);
    }

    public void update(Object bean, final OnResultListener lisentener,
                       Type typeofT) throws IOException {
        OKHttpUtil.getInstance().postAsync(OKHttpUtil.NET_URL + "/api/members/update", bean, new Callback() {
            @Override
            public void onSuccess(Object obj) {
                lisentener.onSuccess(obj);
            }

            @Override
            public void onFailed(Exception e) {
                lisentener.onFails(e);
            }
        },  typeofT);
    }
}
